<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('物料信息管理列表')" />
    <th:block th:include="include :: layout-latest-css" />
    <th:block th:include="include :: ztree-css" />
</head>
<body class="gray-bg">
<div class="ui-layout-west">
    <div class="box box-main">
        <div class="box-header">
            <div class="box-title">
                <i class="fa icon-grid"></i> 类别
            </div>
            <div class="box-tools pull-right">
                <button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i class="fa fa-chevron-up"></i></button>
                <button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i class="fa fa-chevron-down"></i></button>
                <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新"><i class="fa fa-refresh"></i></button>
            </div>
        </div>
        <div class="ui-layout-content">
            <div id="tree" class="ztree"></div>
        </div>
    </div>
</div>
<div class="ui-layout-center">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <input type="hidden" id="deptId" name="deptId">
                    <input type="hidden" id="parentId" name="parentId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>物料编号：</label>
                                <input type="text" name="code"/>
                            </li>
                            <li>
                                <label>物料名称：</label>
                                <input type="text" name="name"/>
                            </li>
                            <li>
                                <label>类型：</label>
                                <select name="type" th:with="type=${@dict.getType('wl_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            </li>

                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="wms:materialInfo:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
               <!-- <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="wms:materialInfo:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>-->
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="wms:materialInfo:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <!--<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="wms:materialInfo:export">
                    <i class="fa fa-download"></i> 导出
                </a>-->
                <a class="btn btn-success" onclick="procure()">
                    <i class="fa fa-plus"></i> 采购申请
                </a>
                <a class="btn btn-success" onclick="ink()">
                    <i class="fa fa-plus"></i> 入库
                </a>
                <a class="btn btn-success" onclick="outk()">
                    <i class="fa fa-plus"></i> 出库
                </a>
                <a class="btn btn-info" onclick="$.table.importExcel()" >
                    <i class="fa fa-upload"></i> 导入
                </a>
                <a class="btn btn-warning" onclick="exportExcelData()">
                    <i class="fa fa-download"></i> 导出
                </a>
                <a onclick="exportData()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载导入模板</a>
                <br/>
                <font color="red">注：使用导入功能前，请待定左边的树再进行导入。</font>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
</div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: layout-latest-js" />
    <th:block th:include="include :: ztree-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('wms:materialInfo:edit')}]];
        var removeFlag = [[${@permission.hasPermi('wms:materialInfo:remove')}]];
        var typeDatas = [[${@dict.getType('wl_type')}]];
        var unitDatas = [[${@dict.getType('wl_unit')}]];
        var statusDatas = [[${@dict.getType('sys_job_status')}]];
        var prefix = ctx + "wms/materialInfo";

        $(function() {
            $(function() {
                var panehHidden = false;
                if ($(this).width() < 769) {
                    panehHidden = true;
                }
                $('body').layout({ initClosed: panehHidden, west__size: 185 });
                // 回到顶部绑定
                if ($.fn.toTop !== undefined) {
                    var opt = {
                        win:$('.ui-layout-center'),
                        doc:$('.ui-layout-center')
                    };
                    $('#scroll-up').toTop(opt);
                }
                queryUserList();
                queryDeptTree();
            });


        });
        function queryUserList() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                importUrl: prefix + "/importData",
                modalName: "物料信息管理",
                columns: [{
                    checkbox: true
                },
                    {
                        field: 'id',
                        title: '用户id',
                        visible: false
                    },{
                        field: 'parentName',
                        title: '仓库'
                    },
                    {
                        field: 'code',
                        title: '物料编号'
                    },
                    {
                        field: 'name',
                        title: '物料名称'
                    },
                    {
                        field: 'model',
                        title: '规格型号'
                    },
                    {
                        field: 'type',
                        title: '类型',
                        formatter: function(value, row, index) {
                            return $.table.selectDictLabel(typeDatas, value);
                        }
                    },
                    {
                        field: 'unit',
                        title: '单位',
                        formatter: function(value, row, index) {
                            return $.table.selectDictLabel(unitDatas, value);
                        }
                    },
                    {
                        field: 'price',
                        title: '单价'
                    },
                    {
                        field: 'total',
                        title: '库存总数'
                    },
                    {
                        field: 'totalPrice',
                        title: '总价'
                    },
                    /*{
                        field: 'status',
                        title: '状态',
                        formatter: function(value, row, index) {
                            return $.table.selectDictLabel(statusDatas, value);
                        }
                    },*/
                    {
                        title: '操作',
                        align: 'center',
                        formatter: function(value, row, index) {
                            var actions = [];
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                            return actions.join('');
                        }
                    }]
            };
            $.table.init(options);
        }

        function queryDeptTree()
        {
            var url = ctx + "wms/materialCategory/treeData";
            var options = {
                url: url,
                expandLevel: 2,
                onClick : zOnClick
            };
            $.tree.init(options);

            function zOnClick(event, treeId, treeNode) {
                $("#deptId").val(treeNode.id);
                $("#parentId").val(treeNode.pId);
                $("#deptId1").val(treeNode.id);
                $.table.search();
            }
        }

        $('#btnExpand').click(function() {
            $._tree.expandAll(true);
            $(this).hide();
            $('#btnCollapse').show();
        });

        $('#btnCollapse').click(function() {
            $._tree.expandAll(false);
            $(this).hide();
            $('#btnExpand').show();
        });

        $('#btnRefresh').click(function() {
            queryDeptTree();
        });
        function procure() {
            $.modal.openTab("采购申请", "/wms/procurehead/add");
        }
        function ink() {
            $.modal.openTab("入库申请", "/wms/inlist/add");
        }
        function outk() {
            $.modal.openTab("出库申请", "/wms/outhead/add");
        }

        function exportData(id) {
            var dataParam = new Array();
            dataParam.push({ "name": "deptId", "value": -1 });
            $.post(prefix+"/export", dataParam, function(result) {
                if (result.code == web_status.SUCCESS) {
                    window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
                } else if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                } else {
                    $.modal.alertError(result.msg);
                }
                $.modal.closeLoading();
            });
        }
    </script>
</body>
<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file" name="file"/>
            <div class="mt10 pt5">
                <input type="hidden" id="deptId1" name="deptId">
                &nbsp;
            </div>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！
            </font>
        </div>
    </form>
</script>

</html>